import axios from 'axios'

const http = axios.create({
  baseURL: '/api',
  timeout: 10000
})

// 根据你的返回结构 { code, message, data }
http.interceptors.response.use(
  (resp) => {
    const r = resp.data
    if (r && r.code === 200) return r.data
    return Promise.reject(new Error(r?.message || '请求失败'))
  },
  (err) => Promise.reject(err)
)

export default http
